home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / osr5 / sco / scripts / oa / oafinger < prev    next >
Encoding:
Text File  |  1997-08-26  |  3.5 KB  |  137 lines

  1. #!/usr/lib/scosh/utilbin/oash
  2. # (was /usr/lib/oa/utilbin/oash)
  3. # @(#) oafinger.oash 1.0.1 97/07/17
  4. # 92/09/09 John H. DuBois III (john@armory.com)
  5. # 92/09/16 Allow selection of multiple users.
  6. # 96/01/19 Use home dir as default tmp dir for safety
  7. # 97/07/17 1.0.1 Search for project files too.  Sort by account name.
  8.  
  9. OALIB=${OALIB-"/usr/lib/oa"}
  10. PATH=$OALIB/utilbin:$PATH
  11.  
  12. # run ourself thru oash 
  13. oainit 2>/dev/null || exec oash $0
  14. #. `findfile shell_strs`
  15.  
  16. : ${TMP:=$TMPDIR}
  17. : ${TMP:=$HOME}
  18. : ${TMP:=/tmp}
  19. FOut=$TMP/#oafing$$o
  20. FList=$TMP/#oafing$$l
  21.  
  22. # $* will be:
  23. # (uuuuuuuu  name )+
  24. # where:
  25. # uuuuuuuu is 8 characters: 0 or more spaces followed by 1 or more nonspaces.
  26. # name is 1-22 characters: no leading or trailing spaces; no runs of more
  27. # than 1 space.  This allows the username,realname pairs to be recognized:
  28. # the usernames are the words followed by two spaces, and everything between
  29. # them are the realnames.
  30. FingerUsers() {
  31.     IFS="
  32. "
  33.     set -- `awk '
  34.     BEGIN {
  35.     # Make sure list starts with space, to make processing easier
  36.     Items = " " ARGV[1]
  37.     Len = length(Items)
  38.     sub(" +$","",Items)    # Get rid of trailing spaces
  39.     N = U = 1
  40.     # Iteratively peel real names off of the end of the list
  41.     # (everthing from the last two-space string in the list to the end of
  42.     # the list) and then usernames from the end of the list (the username
  43.     # being the word that precedes the realname).
  44.  
  45.     # match two spaces followed by any number of word+single-space strings
  46.     # followed by a word followed by the end of the string.  This will be
  47.     # the trailing real-name.
  48.     while (match(substr(Items,1,Len),"  ([^ ]+ )+[^ ]+$")) {
  49.         Name = substr(Items,RSTART + 2,RLENGTH - 2)
  50.         sub(" +$","",Name)
  51.         Names[N++] = Name
  52.         Len = RSTART - 1
  53.         # Get the username.
  54.         match(substr(Items,1,Len)," +[^ ]+$")
  55.         User = substr(Items,RSTART,RLENGTH)
  56.         sub(" +$","",User)
  57.         sub("^ +","",User)
  58.         Users[U++] = User
  59.         Len = RSTART - 1
  60.     }
  61.     while (--N)
  62.         print Users[N] "\n" Names[N]
  63.     }
  64.     ' "$*"`
  65.  
  66.     if [ $# -gt 1 ]; then
  67.     wmopen 2 $WinSz 79 0 0  
  68.     wmmessage -r "Use arrow keys; <esc> to finish reading"
  69.     fi
  70.  
  71.     while [ $# -gt 1 ]; do
  72.     UserName=$1
  73.     # Use sed to extract only the first copy of finger file if finger
  74.     # prints more than one due to user being logged in multiple times
  75.     finger $UserName |sed -n '1p;1n;/^Login name: /q;p' > $FOut 2>&1
  76.  
  77.     if test ! -s $FOut; then
  78.        echo "No information on user." >> $FOut
  79.     fi
  80.     echo c
  81.  
  82.     wmtitle "$2's Self Description"
  83.     scan -eEND $FOut
  84.     shift 2
  85.     done
  86. }
  87.  
  88. [ -z "$LINES" ] && LINES=`tput lines`
  89. WinSz=$LINES
  90. #WinSz=`expr $LINES - 1`
  91.  
  92. echo -n "Searching for finger files..."
  93. wrefresh
  94.  
  95. awk -F: '
  96. !($6 in HomeDirs) {
  97.     HomeDirs[$6]
  98.     Plan = $6 "/.plan"
  99.     Project = $6 "/.project"
  100.     if ((getline planline < Plan) == 1 || (getline projline < Project) == 1) {
  101.     sub(",.*","",$5)
  102.     # Make sure there are no multiple spaces in name since two
  103.     # spaces are used to distinguish items in PP_ITEM (ewww)
  104.     gsub("  +"," ",$5)
  105.     sub("^ +","",$5)
  106.     sub(" +$","",$5)
  107.     if ($5 == "")
  108.         $5 = $1
  109.     printf "%8s  %s\n",$1,substr($5,1,22)
  110.     }
  111.     close(Plan)
  112.     close(Project)
  113. }' /etc/passwd | sort -b +0 -1 > $FList
  114.  
  115. if [ ! -s $FList ]; then
  116.     oadeinit
  117.     echo "No users have plans."
  118.     rm -f $FList 
  119.     exit
  120. fi
  121.  
  122. wmopen 1 $WinSz 79 0 0
  123. wmtitle "Select up to 15 Users"
  124. wmmessage -r \
  125. "Use arrow keys; <space> selects; <Return> when done selecting; <esc> to quit"
  126.  
  127. pp -m -f $FList
  128. while [ -n "$PP_ITEM" ]; do
  129.     FingerUsers "$PP_ITEM"
  130.     wmove 1
  131.     wrefresh 1
  132.     pp -m -f $FList
  133. done
  134.  
  135. rm -f $FList $FOut
  136. oadeinit
  137.